<script>
	export default {
		onLaunch: function({path}) {
			this.routerIntercept(path)
		},
		methods:{
			routerIntercept (path){
				const whitelist=[
					"/",
					"/#/",
					"pages/tabBar/home/home",
					"/pages/tabBar/home/home",
					"/pages/login/login",
					"pages/login/login",
					"/pages/login/usernamePasswordLogin",
					"pages/login/usernamePasswordLogin",
					"/pages/login/login",
					"/pages/tabBar/user/user",
					"pages/tabBar/user/user"
					// "/pages/list/list"
				]
				const methodToPatch = [
					"navigateTo", "redirectTo", "switchTab", "navigateBack"
				];
				const thia=this
				
				methodToPatch.map((type) => {//首次进入页面也应该进行判断
					uni.addInterceptor(type, {
						invoke(p) {
							if(p.from==="backbutton"){
								return true
							}
							const {url}=p
							console.log("p: ",p);
							console.log("url: ",url);
							if(whitelist.includes(url)===true){
								return true
							}else{//不是白名单的路由
								if (thia.$store.state.isLogin===false) {//未登录
								/**
								 * whitelist.includes(url)===false
								 * 白名单中不存在访问的url
								 * */
									console.log("跳转: ");
									uni.navigateTo({
										url: "/pages/login/login",
									});
									return false
								}
							}
							
							return true
						},
						success(args) {
						},
						fail(err) {},
						complete(res) {}
					})
				});
				const url=path
				if(whitelist.includes(url)===true){
					return true
				}else{//不是白名单的路由
					if (thia.$store.state.isLogin===false) {//未登录
					/**
					 * whitelist.includes(url)===false
					 * 白名单中不存在访问的url
					 * */
						uni.navigateTo({
							url: "/pages/login/login",
						});
						return true
					}
				}
			},
		},
		onShow: function() {},
		onHide: function() {}
	}
</script>

<style>
	/*每个页面公共css */
</style>
